﻿/*
This file is under Microsoft Public License (MS-PL)
Copyright Yohann MARTEL.  All rights reserved.
Codeplex: http://amf.codeplex.com
AMF Website: http://www.ymartel.com/aspnet-mobile-framework/
*/
using System;
using System.Web.UI;

namespace Mobile.WebControls.Field
{
    internal class FlipToggleSwitchControl : ThemedControl
    {
        #region Properties
        public string FieldName { get; set; }
        public string OptionOneValue { get; set; }
        public string OptionOneText { get; set; }
        public string OptionTwoValue { get; set; }
        public string OptionTwoText { get; set; }
        #endregion

        #region Methods
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            SelectOption selectOptionOne = new SelectOption();
            selectOptionOne.Value = OptionOneValue;
            selectOptionOne.Text = OptionOneText;
            SelectOption selectOptionTwo = new SelectOption();
            selectOptionTwo.Value = OptionTwoValue;
            selectOptionTwo.Text = OptionTwoText;
            Controls.Add(selectOptionOne);
            Controls.Add(selectOptionTwo);
        }
        #endregion

        #region Render Methods
        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            AddAttributesToRender(writer);
            writer.RenderBeginTag(HtmlTextWriterTag.Select);
        }

        public override void RenderEndTag(HtmlTextWriter writer)
        {
            writer.RenderEndTag();
        }

        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            writer.AddAttribute(MetadataAttribute.DataRole, DataRole.Slider);
            if (!String.IsNullOrEmpty(FieldName))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Name, FieldName);
            }
        }
        #endregion
    }
}
